﻿<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<IList<Prodma.DataAccess.Models.ViewModels.UrunlerVm>>" %>

        <div class="listTitleContainer">
            <div class="listTitleCenter-50">#</div>
            <div class="listTitleCenter-150">Urun Adı</div>
            <div class="listTitleCenter-150">Urun Kodu</div>
            <%--<div class="listTitleCenter-150">Marka</div>--%>
            <div class="listTitleCenter-50">Fiyat</div>   
            <div class="listTitleCenter-50">Fotoğraf</div>
        </div>

        <div class="listRowContainer">
        <% string p = Request.QueryString.Get("p");
           if (p == null || p == "" || p.StartsWith("-") || p == "0")
           {
               p = "1";
        } %>
        <% int counter = (Convert.ToInt32(Request.QueryString.Get("p")) - 1) * Convert.ToInt32(Request.QueryString.Get("ps")) + 1;
            if (counter < 1){
                counter = 1;
            }
        %>
        <% TimeSpan oneWeek = new TimeSpan(4, 12, 0, 0) + new TimeSpan(2, 12, 0, 0); %>
        <% foreach (Prodma.DataAccess.Models.ViewModels.UrunlerVm urunler in ViewData.Model) %>
        <% { %>
             <% if (counter % 2 != 0) %>
             <% { %>
                  <div class="listRow1" ondblclick="doubleClick(<%=urunler.ID %>)">
                      <div class="listColumnCenter-50"><%=counter%></div>
                      <%--<div class="listColumnCenter-50">
                        <a onclick="formSubmit(<%=counter%>)" >
                            <img src="../../Images/MenuIcons/shoppingcart.png" alt="sepet"/>
                        </a>
                      </div>--%>
                      <%--<div class="listColumnCenter-50">
                              <input type="text" id='Text<%=counter %>' name='Text<%=counter %>' maxlength="2" value="1"
                              class="detailSectionControl" style="width: 25px" />
                              <input type="hidden" value="<%=urunler.ID %>" name='Product<%=counter %>' /></div>--%>
                      <div class="listColumnCenter-150"><a href="/Urunler/ProductDetail/<%=urunler.ID %>"><%=urunler.UrunAdi%></a> </div>
                      <div class="listColumnCenter-150" ><%=urunler.UrunKodu%>
                        <% if (urunler.InsertDate > DateTime.Now - oneWeek)
                           { %><img src="../../../Images/ListImages/NewProduct.png" /><%} %>
                      </div>
                      <%--<div class="listColumnCenter-150"><%=urunler.Marka.MarkaAdi%></div>--%>
                      <div class="listColumnCenter-50"><%=urunler.Fiyat%></div>
                      <div class="listColumnCenter-50">
                        <a class="thumbnail" href="/Urunler/ProductDetail/<%=urunler.ID %>">
                            <img src="<%=urunler.ThumbURL %>" /><span><img src="<%=urunler.FotoURL %>"/></span>                            
                        </a>
                      </div>
                  </div>
             <% } %>
             <% else %>
             <% { %>
                  <div class="listRow2" ondblclick="doubleClick(<%=urunler.ID %>)">
                      <div class="listColumnCenter-50"><%=counter%></div>
                      <%--<div class="listColumnCenter-50">
                        <a onclick="formSubmit(<%=counter %>)">
                            <img src="../../Images/MenuIcons/shoppingcart.png" alt="sepet"/>
                        </a>
                      </div>--%>
                      <%--<div class="listColumnCenter-50">
                        <input type="text" id='Text<%=counter %>' name='Text<%=counter %>' maxlength="2" value="1"
                              class="detailSectionControl" style="width: 25px"/>
                         <input type="hidden" value="<%=urunler.ID %>" name='Product<%=counter %>' /></div>--%>
                      <div class="listColumnCenter-150"><a href="/Urunler/ProductDetail/<%=urunler.ID %>"><%=urunler.UrunAdi%></a> </div>
                      <div class="listColumnCenter-150"><%=urunler.UrunKodu%>
                        <% if (urunler.InsertDate > DateTime.Now - oneWeek)
                           { %><img src="../../../Images/ListImages/NewProduct.png" /><%} %>
                      </div>
                      <%--<div class="listColumnCenter-150"><%=urunler.Marka.MarkaAdi%></div>--%>
                      <div class="listColumnCenter-50"><%=urunler.Fiyat%></div>
                      <div class="listColumnCenter-50">
                        <a class="thumbnail" href="/Urunler/ProductDetail/<%=urunler.ID %>">
                            <img src="<%=urunler.ThumbURL %>" /><span><img src="<%=urunler.FotoURL %>"/></span>                      
                        </a>
                      </div>
                  </div>
             <% } %>
             <% counter++; %>
        <% } %>
    <% string pageSize = Request.QueryString.Get("ps");
       if (pageSize == null || pageSize == "")
       {
          pageSize="10";
          
       }%>       
    </div>
    <div class="listRowContainer">
        <table>
            <tr>
                <td>   
                    <a href="./?ps=<%=pageSize%>">first</a>
                </td>
                <td>   
                    <a href='./?p=<%=Convert.ToInt32(p)-1+"&ps="+pageSize%>'>prev</a>
                </td>
                <td>   
                    <input type="text" id="currentPage" value='<%=p %>'/>
                    <input type="button" value='Go' onclick="goToPage()"/>
                </td>
                <td>   
                    <a href='./?p=<%=Convert.ToInt32(p)+1+"&ps="+pageSize%>'>next</a>
                </td>
                 <td>   
                   <a href='./?p=<%=Convert.ToInt32(ViewData["ListLenght"])+"&ps="+pageSize%>'>last</a>
                </td>
                <td>   
                    &nbsp;
                </td>
                <td>   
                    <select id="dd_pageSize" onchange="changePageSize()">
                        <option value="10">10</option>
                        <option value="25">25</option>
                        <option value="50">50</option>
                        <option value="100">100</option>
                        <option value="-1">All</option>
                    </select>
                </td>
                <td>
                    <%= ViewData["ListLenght"]%>
                </td>
            </tr>
        </table>
    </div>

  <script type="text/javascript">
      $(document).ready(function () {
          $("#dd_pageSize").val('<%=Request.QueryString.Get("ps") %>');
      });
      function changePageSize() {
          window.location = "./?p=" + $("#currentPage").val() + "&ps=" + $("#dd_pageSize").val(); 
          //window.dd_pageSize.value = $("#dd_pageSize").val(); calismiyor.
    }
    function goToPage() {
       window.location = "./?p=" + $("#currentPage").val()+"&ps="+$("#dd_pageSize").val();
    }
    function ageprompt() {
     agewindow = dhtmlmodal.open('agebox', 'div', 'modalalertdiv', 'Age Check', 'width=350px,height=150px,left=150px,top=100px,resize=0,scrolling=0')
    }

    function process_age(whichbutton) {
     if (whichbutton == "no")
         alert("You are under 13 yrs old")
         agewindow.hide()
    }


//    $(window).load(function () {
//        var queryString = window.top.location.search.substring(1);
//        var parameterName = "ps=";
//        var begin = 1;
//        var end = 1;
//        if (queryString.length > 0) {
//            begin = queryString.indexOf(parameterName);
//            alert(begin);
//            if (begin != -1) {
//                begin += parameterName.length;
//                end = queryString.indexOf("&", begin);
//                if (end == -1) {
//                    end = queryString.length
//                }
//            }
//        }
//        alert("load");
//        alert(queryString.substring(begin, end));
//        if (queryString.substring(begin, end) == 10) {
//            document.getElementById("dd_pageSize").options[0].selected = true;
//        }
//        else if (queryString.substring(begin, end) == 25) {
//            document.getElementById("dd_pageSize").options[1].selected = true;
//        }
//        else if (queryString.substring(begin, end) == 50) {
//            document.getElementById("dd_pageSize").options[2].selected = true;
//        }
//        else if (queryString.substring(begin, end) == 100) {
//            document.getElementById("dd_pageSize").options[3].selected = true;
//        }


//        //document.getElementById("dd_pageSize").options[3].selected = true;
//    });
</script>

        
        
  </script>    